﻿#include <iostream>
using namespace std;
#include<math.h>
#include<queue>

#include<vector>
#include<unordered_map>

//拓补序未做对
//给定一个包含n个点m条边的有向无环图，求出该图的拓扑序。若图的拓扑序不唯一，输出任意合法的拓扑序即可。若该图不能拓扑排序，输出−1。

int main()
{
    unordered_map<int, vector<int>>hash;
    int n, m;
    cin >> n >> m;
    vector<int>in(n + 1, 0);
    while (m--)
    {
        int a, b;
        cin >> a >> b;
        hash[a].push_back(b);
        in[b]++;
    }
    queue<int>q;
    for (int i = 1; i <= n; ++i)
    {
        if (in[i] == 0)
        {
            q.push(i);
        }
    }
    vector<int>ret;
    while (!q.empty())
    {
        int x = q.front();
        q.pop();
        ret.push_back(x);
        for (auto it : hash[x])
        {
            in[it]--;
            if (in[it] == 0)
            {
                q.push(it);
            }
        }
    }

    if (ret.size() != n)
    {
        cout << -1 << endl;
    }
    else
    {
        for (int i = 0; i < n - 1; ++i)
        {
            cout << ret[i] << " ";
        }
        cout << ret[n - 1];
    }
    return 0;
}

//分组，未做对

#include<set>

int main()
{
    ll n, m;
    cin >> n >> m;
    vector<ll>arr(n, 0);
    unordered_map<ll, ll>hash;
    ll Max = 0, num = 0;
    set<ll>x;
    for (int i = 0; i < n; ++i)
    {
        cin >> arr[i];
        x.insert(arr[i]);
        if (hash[arr[i]] == 0)
        {
            num++;
        }
        hash[arr[i]]++;
    }
    for (int i = 0; i < n; ++i)
    {
        if (Max < hash[arr[i]])
        {
            Max = hash[arr[i]];
        }
    }
    if (num > m)
    {
        cout << -1;
    }
    else if (num == m)
    {
        cout << Max;
    }
    else
    {
        ll left = 1, right = Max;
        while (left < right)
        {
            ll mid = (left + right) / 2;
            ll sum = 0;
            for (auto it : x)
            {
                ll m = hash[it] / mid + (hash[it] % mid == 0 ? 0 : 1);
                sum += m;
            }
            if (sum > m)
            {
                left = mid + 1;
            }
            else
            {
                right = mid;
            }
        }
        cout << left;
    }
    return 0;
}


//int main()
//{
//    ll n;
//    cin >> n;
//    ll ret = sqrt(n);
//    ret = (n - ret * ret) < ((ret + 1) * (ret + 1) - n) ? ret * ret : (ret + 1) * (ret + 1);
//    cout << ret;
//}